﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Things.Common;
using LTP.Accounts.Bus;
namespace Things.ThingsWeb.GoodsOrders
{
    public partial class Add : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                       
        }

        		protected void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtBuyerAccount.Text.Trim().Length==0)
			{
				strErr+="用户帐号不能为空！\\n";	
			}
			if(this.txtBuyerAddress.Text.Trim().Length==0)
			{
				strErr+="收货地址不能为空！\\n";	
			}
			if(!PageValidate.IsDecimal(txtTotalPrice.Text))
			{
				strErr+="订单金额格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtBuyDate.Text))
			{
				strErr+="购买日期格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtSendDate.Text))
			{
				strErr+="SendDate格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtCancelDate.Text))
			{
				strErr+="CancelDate格式错误！\\n";	
			}
			if(this.txtStatus.Text.Trim().Length==0)
			{
				strErr+="Status不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtModifiedDate.Text))
			{
				strErr+="最新变更时间格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			string BuyerAccount=this.txtBuyerAccount.Text;
			string BuyerAddress=this.txtBuyerAddress.Text;
			decimal TotalPrice=decimal.Parse(this.txtTotalPrice.Text);
			DateTime BuyDate=DateTime.Parse(this.txtBuyDate.Text);
			DateTime SendDate=DateTime.Parse(this.txtSendDate.Text);
			DateTime CancelDate=DateTime.Parse(this.txtCancelDate.Text);
			string Status=this.txtStatus.Text;
			bool IsCompleted=this.chkIsCompleted.Checked;
			DateTime ModifiedDate=DateTime.Parse(this.txtModifiedDate.Text);

			Things.Model.GoodsOrders model=new Things.Model.GoodsOrders();
            model.GoodsOrdersID = Guid.NewGuid();
			model.BuyerAccount=BuyerAccount;
			model.BuyerAddress=BuyerAddress;
			model.TotalPrice=TotalPrice;
			model.BuyDate=BuyDate;
			model.SendDate=SendDate;
			model.CancelDate=CancelDate;
			model.Status=Status;
			model.IsCompleted=IsCompleted;
			model.ModifiedDate=ModifiedDate;

			Things.BLL.GoodsOrders bll=new Things.BLL.GoodsOrders();
			bll.Add(model);
			Things.Common.MessageBox.ShowAndRedirect(this,"保存成功！","add.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
